// pages/index/abc/index.js
import {list as wxPageList} from '../../../../api/wxPage'
import {list as navigationList} from '../../../../api/navigation'
const util = require('../../../../utils/util.js')
let app = getApp();
Component({
  /**
   * 组件的属性列表
   */
  properties: {
			info:{
				type:Object
			}
  },
		lifetimes:{
			attached(){
        if (this.data.info.tagids != null) {
					this.data.tagIds = this.data.info.tagids.split(',')
					for (var i = 0; i < this.data.tagIds.length; i++) {
						this.data.tagIds[i] = parseInt(this.data.tagIds[i])
					}
				}
          this.setData({
            tagIds:this.data.tagIds
          })
				
				this.loadNavigation()
				this.loadPage()
      }
				
		},
  /**
   * 组件的初始数据
   */
  data: {
		tagIds:[],
		pageSize:4,
		pageList:[],
		navigations:[],
	welfareList: [
		{
			text: '家居用品',
			img: ''
		},
		{
			text: '数码家电',
			img: ''
		},
		{
			text: '洗护用品',
			img: ''
		},
		{
			text: '中秋美食',
			img: ''
		},
	]
  },
  created(){

  },
  /**
   * 组件的方法列表
   */
  methods: {
		toItem(e){
			wx.navigateTo({
				url: '/pages/index/wxPage/wxPage?id='+e.currentTarget.dataset.id
		})
		},
		loadNavigation(){
			navigationList({
				tagIds:this.data.tagIds,
				pageSize:this.data.pageSize,
				mchId:app.globalData.mchId
			}).then(res=>{
				this.data.navigations=res.data.data
				this.setData({
					navigations:this.data.navigations
				})
			})
		},
		loadPage(){
			var _this = this;
      wxPageList({
				mchId:app.globalData.mchId,
				tagIds:this.data.tagIds,
			}).then(res=>{
				_this.data.pageList=res.data.data
				_this.data.pageList[0].thumbnial = util.thumbnail(_this.data.pageList[0].thumbnial,710,355)
				console.log("扶贫专区的数据")
				console.log(_this.data.pageList)
			_this.setData({
            pageList:_this.data.pageList
          })
      })
    },
	itemClick (item) {
		console.log(item)
		if(item.currentTarget.dataset.index.type==1){
			wx.navigateTo({
				url: '/pages/goods/category/category?id='+item.currentTarget.dataset.index.typeId
		 })
		}
		if (item.currentTarget.dataset.index.type == 2) {
			wx.navigateTo({
				url: '/pages/index/wxPage/wxPage?id=' + item.currentTarget.dataset.index.typeId
			})
		}
		if(item.currentTarget.dataset.index.type==3){
			wx.navigateTo({
				url: '/pages/goods/product/details?id='+item.currentTarget.dataset.index.typeId,
			})
		}
	}
  }
})
